package cn.itcast.web.controller.cargo;

import cn.itcast.domain.cargo.Export;
import cn.itcast.domain.cargo.ShipOrder;
import cn.itcast.domain.cargo.ShipOrderExample;
import cn.itcast.service.cargo.ShipOrderService;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/cargo/shipping")
@Log4j
public class ShippingController extends BaseController {
    @Reference
    private ShipOrderService shipOrderService;

    //功能入口
    @RequestMapping("list")
    public String list(String id,
                        @RequestParam(defaultValue = "1")Integer pageNum,
                       @RequestParam(defaultValue = "5")Integer pageSize){
     /*   log.info("执行委托单查询开始");
        //创建查询对象
        ShipOrderExample example = new ShipOrderExample();
        //按创建时间添加
        example.setOrderByClause("create_time desc");

        //添加查询条件  一个装箱单对应一个委托单
        example.createCriteria().andShippingOrderIdEqualTo(id);

        //分页查询
        PageInfo<ShipOrder> pageInfo = shipOrderService.findByPage(example,pageNum,pageSize);

        //保存数据
        request.setAttribute("pageInfo",pageInfo);*/

        return "cargo/ship/ship-list";
    }

    //进入添加
    @RequestMapping("/toAdd")
    public String toAdd(){

        return "cargo/ship/ship-add";
    }

    //添加或修改
    @RequestMapping("/edit")
    public  String edit(ShipOrder shipOrder){
      //判断是更新还是添加
        if(StringUtils.isEmpty(shipOrder.getShippingOrderId())){
            //添加
            shipOrderService.save(shipOrder);
        }else {
            shipOrderService.update(shipOrder);
        }

        return "redirect:/cargo/shipping/list";
    }


    //导出excel
    @RequestMapping("/print")
    public String print(){

        return "cargo/print/ship-print";
    }
    /*@RequestMapping("/submit")
    public String submit(String id) {
        Export export = new Export();
        export.setId(id);
        // 修改状态：已提交的购销合同才可以电子报运
        export.setState(1);
        exportService.update(export);
        return "redirect:/cargo/export/list";
    }
    @RequestMapping("/cancel")
    public String cancel(String id) {
        Export export = new Export();
        export.setId(id);
        // 修改状态：设置状态为0草稿
        export.setState(0);
        exportService.update(export);
        return "redirect:/cargo/export/list";
    }
*/
}
